package net.jsoft.platform.oauth2.web.github;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import net.jsoft.platform.core.util.spring.SpringUtil;
import net.jsoft.platform.core.web.BaseController;
import net.jsoft.platform.oauth2.service.IThirdPartyLoginService;

@Controller
@RequestMapping("/oauth2")
public class ThirdPartyControllor extends BaseController
{

    @RequestMapping("/afterBind")
    public void afterBind(HttpServletRequest request)
    {
        String userId = null;

        String type = request.getParameter("type");

        switch (type)
        {
        case "github":
        {
            IThirdPartyLoginService service = (IThirdPartyLoginService) SpringUtil.getBean("githubService");
            String code = request.getParameter("code");
            userId = service.getUser(code);
            break;
        }
        case "weibo":
        {
            IThirdPartyLoginService service = (IThirdPartyLoginService) SpringUtil.getBean("weiboService");
            String code = request.getParameter("code");
            userId = service.getUser(code);
            break;
        }
        case "qq":
        {
            IThirdPartyLoginService service = (IThirdPartyLoginService) SpringUtil.getBean("qqService");
            String code = request.getParameter("code");
            userId = service.getUser(code);
            break;
        }
        case "facebook":
        {
            userId = request.getParameter("id");
            break;
        }

        }
        //        System.out.println(userId);

        //1查询当前是否有用户 ？ 直接登录 ：  没有提示
        if (StringUtils.isNotEmpty(userId))
        {

        }

        // 2是否已注册？  关联用户 ： 注册账户

    }
}
